package huoye.shops.huoye.mine.presenter;


import android.util.Log;

import java.util.List;

import huoye.shops.base.BasePresenter;
import huoye.shops.base.MineBaseJsonRequestCallback;
import huoye.shops.common.model.OssImageData;
import huoye.shops.huoye.mine.model.ContractData;
import huoye.shops.huoye.mine.model.EnterPactData;
import huoye.shops.huoye.mine.model.ShopDetials;
import huoye.shops.huoye.mine.networt.MineService;
import huoye.shops.huoye.mine.view.IEnterPactView;
import huoye.shops.huoye.mine.view.IShopMessageView;


/**
 * Created by uesr on 2017/7/19.
 */

public class EnterPactPresenter extends BasePresenter<IEnterPactView> {


    private MineService mService;

    //商家补全合同信息
    public void SetContract(List<String> contractImgs){
        mService.SetContract(contractImgs, new MineBaseJsonRequestCallback<ContractData>(ContractData.class) {
            @Override
            public void onSuccess() {
                super.onSuccess();
                view.makeToast("合同补全成功");
                view.finish();
            }

            //网络请求失败
            @Override
            public void onFailure(String msg, String code, Throwable e) {
                super.onFailure(msg, code, e);
                view.makeToast(msg);
            }

            //加载结束
            @Override
            public void onNetworkFail() {
                super.onNetworkFail();
                view.onNetworkFail();
            }

            //加载中
            @Override
            public void onFinish() {
                super.onFinish();
                view.hideProcessingIndicator();
            }
        });
    }




    //获取商家合同信息
    public void contractInfo(){
        mService.contractInfo( new MineBaseJsonRequestCallback<EnterPactData>(EnterPactData.class) {
            @Override
            public void onSuccess(EnterPactData enterPactData) {
                super.onSuccess(enterPactData);
                view.getContractData(enterPactData);
            }

            //网络请求失败
            @Override
            public void onFailure(String msg, String code, Throwable e) {
                super.onFailure(msg, code, e);
                view.makeToast(msg);
            }

            //加载结束
            @Override
            public void onNetworkFail() {
                super.onNetworkFail();
                view.onNetworkFail();
            }

            //加载中
            @Override
            public void onFinish() {
                super.onFinish();
                view.hideProcessingIndicator();
            }
        });
    }






    //图片上传
    public void uploadOssImg(String id,String type,String filePath){
        //  view.showProcessingIndicator();
        mService.uploadOssImg(id,type,filePath,new MineBaseJsonRequestCallback<OssImageData>(OssImageData.class) {

            @Override
            public void onSuccess(List<OssImageData> list) {
                super.onSuccess(list);
                Log.e("test",list.get(0).toString());
                OssImageData ossImageData = list.get(0);
                view.setUpload(ossImageData);
            }

            //网络请求失败
            @Override
            public void onFailure(String msg, String code, Throwable e) {
                super.onFailure(msg, code, e);
                view.makeToast(msg);
            }

            //加载结束
            @Override
            public void onNetworkFail() {
                super.onNetworkFail();
                view.onNetworkFail();
            }

            //加载中
            @Override
            public void onFinish() {
                super.onFinish();
                view.hideProcessingIndicator();
            }
        });

    }


    //图片删除
    public void deleteOssImg(String filePath){
        //  view.showProcessingIndicator();
        mService.deleteOssImg(filePath,new MineBaseJsonRequestCallback<OssImageData>(OssImageData.class) {

            @Override
            public void onSuccess() {
                super.onSuccess();
                view.makeToast("OSS图片删除成功！");
                view.setDelete();
            }

            //网络请求失败
            @Override
            public void onFailure(String msg, String code, Throwable e) {
                super.onFailure(msg, code, e);
                view.makeToast(msg);
            }

            //加载结束
            @Override
            public void onNetworkFail() {
                super.onNetworkFail();
                view.onNetworkFail();
            }

            //加载中
            @Override
            public void onFinish() {
                super.onFinish();
                view.hideProcessingIndicator();
            }
        });

    }












    @Override
    public void onStart() {
        mService = new MineService();
    }
}
